<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style>
        .box {
            padding: 0 50px;
            display: flex;
            flex-direction: column;
        }

        .title {
            width: 100%;
            text-align: center;
            font-size: 18px;
            font-weight: 700;
            color: #e6c678;
        }

        .form {
            width: 100%;
            /* flex: 1; */
        }

        .table {
            padding-bottom: 20px;
            flex: 1;
        }

        .table table tr td {
            text-align: center;
        }

        .van-field {
            width: 33.33%;
            float: left;
        }

        .van-cell {
            background-color: transparent;
        }

        .van-field__control {
            border-bottom: 2px solid #e6c678;
        }

        .van-cell::after {
            border-bottom: 0;
        }

        input {
            background: none;
            outline: none;
            border: none;
        }

        .bottomBtns {
            width: 100%;
            left: 0;
            /* display: flex; */
            position: fixed;
            bottom: 0;
        }

        .bottomBtns .van-button {
            margin: auto;
            width: 60%;
        }

        .scanPop {
            width: 160px;
            height: 180px;
            text-align: center;
            background-color: transparent;
            margin: 0;
            padding: 0;
        }

        .scanLine {
            position: absolute;
            z-index: 2;
            width: 66%;
            height: 2px;
            transform: translateX(25%);
            background-color: #e6c678;
            animation: scanLineMove 2s infinite;
        }


        @keyframes scanLineMove {
            from {
                top: 30px;
            }

            to {
                top: 120px;
            }
        }

        .inputClass {
            opacity: 0;
            width: 150px;
        }

        .van-icon-enlarge {
            font-size: 150px;
            color: #e6c678;
            margin: 0;
            padding: 0;
        }

        .add {
            position: fixed;
            bottom: 80px;
            right: 20px;
            width: 40px;
            height: 40px;
            border-radius: 40px;
            text-align: center;
            line-height: 44px;
            background: #e6c678;
            color: #fff;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <div class="title">试模新增修改明细</div>

            <div class="form">
                <van-field v-model="formData.StartTime" label="记录日期：" readonly></van-field>
                <van-field v-model="formData.CreateTime" label="开始时间：" readonly @click='addTime("开始时间")'></van-field>
                <van-field v-model="formData.EndTime" label="结束时间：" readonly @click='addTime("结束时间")'></van-field>
                <van-field v-model="formData.EquipmentCode" label="机台编号：" readonly @click="openBaseScreen('机台')">
                </van-field>
                <van-field label="模具编号:" v-model="formData.MouldNo" @click="openBaseScreen('模具')">
                </van-field>
                <van-field label="产品名称:" v-model="formData.ProductName">
                </van-field>
                <van-field label="本月试制数:" v-model="formData.BYSZNum">
                </van-field>
                <van-field label="累计试制数:" v-model="formData.LJSZNum">
                </van-field>
                <van-field v-model="formData.Creater" label="试模人：" placeholder="请输入试模人">
                </van-field>
                <!-- <van-field v-model="formData.Creater" label="试模人：" placeholder="请输入试模人" readonly @click='addUserName'>
                </van-field> -->
                <van-field v-model="formData.Purpose " label="试制目的：" placeholder="请输入试制目的">
                </van-field>
                <van-field v-model="formData.Result" label="试制结果：" placeholder="请输入试制结果" readonly
                    @click="openshowSearch">
                </van-field>
                <van-field style="width: 100%;" v-model="formData.WTContent" label="试制问题点：" placeholder="请输入试制问题点">
                </van-field>
                <van-field style="width: 100%;" v-model="formData.WTFXContent" label="问题点分析：" placeholder="请输入问题点分析">
                </van-field>
                <!-- <van-field v-model="formData.ApproveName" label="试模人：" placeholder="请输入试模人" readonly
                    @click="openBaseScreen('试模人')"></van-field> -->
                <!-- <van-field v-model="formData.Remarks" label="备注：" placeholder="请输入备注"></van-field> -->
                      <!-- <van-field v-model="formData.qwe" label="启用刷卡：" placeholder="请输入试模人" readonly @click='addUserName'>
                </van-field> -->
            </div>

            <div class="add" @click='go'>
                <van-icon name="plus"></van-icon>
            </div>
            <div class="bottomBtns">
                <van-button v-if="!formData.CreateTime " color="linear-gradient(#fffeaa, #c07d39)" type="primary" block
                    @click="addsubmit">
                    开始按钮
                </van-button>
                <van-button v-else-if="formData.CreateTime && !formData.EndTime"  color="linear-gradient(#fffeaa, #c07d39)" type="primary" block @click="endsubmit">
                    结束按钮 </van-button>
            </div>
        </div>

        <van-popup v-model="showTime" position="bottom">
            <!-- <van-datetime-picker v-model="currentDate" type="date" title="选择年月日" @confirm="confirmTime"
                @cancel="showTime = false"></van-datetime-picker> -->

            <van-datetime-picker v-model="currentDate" type="datetime" title="选择完整时间" @confirm="confirmTime"
                @cancel="showTime = false" />
        </van-popup>


        <van-action-sheet v-model="classShow" :actions="classOptions" @select="onSelectClass"></van-action-sheet>
        </van-action-sheet>
        <van-action-sheet v-model="showSearch" :actions="IControlActions" @select="onSelectIControl">
        </van-action-sheet>
        <van-popup v-model="scanShow" class="scanPop">
            <div class="scanLine"></div>
            <van-icon name="enlarge"></van-icon>
            <input id="autoInput" class="inputClass" inputmode="none" type="number" v-model="inputCode" ref="input"
                autofocus @keyup.enter="inputFocus()">
        </van-popup>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            var type = ret.value.type;
            var row = ret.value.row;

            if (type == '机台') {
                vm.formData.EquipmentName = row.EquipmentName;
                vm.formData.EquipmentCode = row.EquipmentCode;
                vm.formData.EquipmentID = row.EquipmentID;
            }

            else if (type == '模具') {
                vm.formData.MouldNo = row.MouldNo;
                vm.formData.mouldid = row.MouldID;
            }

            else if (type == '原材料') {
                vm.tableData[vm.currentIndex].ProductName = row.ProductName;
                vm.tableData[vm.currentIndex].ProductCode = row.ProductCode;
                if (vm.currentIndex == 0) {
                    vm.formData.MinTemperature = row.MinTemperature
                    vm.formData.MaxTemperature = row.MaxTemperature
                }
            }
        })
        api.addEventListener({
            name: 'gorefreshBrowser'
        }, function (ret, err) {
            api.sendEvent({
                name: 'refreshBrowser',
                extra: {
                    breadData: {
                        name: '试模明细',
                        url: 'TryoutDetails',
                        ZS_FunctionID: 0,
                        click: true
                    }
                }
            })
            api.closeFrame()
        })


        vm = new Vue({
            el: '#app',
            data: {
                showTime: false,
                currentDate: new Date(),
                buttonShow: 1,
                showSearch: false,
                showSearchIndex: 0,
                formData: {
                    CreateTime: '',
                    EndTime: '',
                    MouldNo: '',
                    mouldid: '',
                    EquipmentID: '',
                    EquipmentName: '',
                    EquipmentCode: '',
                    LJSZNum: '',
                    BYSZNum: '',
                    ProductName: '',
                    StartTime: APP.getFormatDateTime(new Date()),
                    EmplName: '',
                    Creater: window.localStorage.getItem('loginName'),
                    Result: '',
                    Purpose: '',
                    WTContent: '',
                    WTFXContent: '',
                    qwe:''
                },
                // formData: {
                //     MouldNo: '',
                //     mouldid: '',
                //     EquipmentID: '',
                //     EquipmentName: '',
                //     empolorName: window.localStorage.getItem('loginName'),
                //     WhiteORNight: '',
                //     class: '',
                //     StartTime: APP.getFormatDateTime(new Date()),
                //     Result: '',
                //     ResultVal: '',
                //     Colour: '',
                //     CheckTemperature: '',
                //     MinTemperature: '',
                //     MaxTemperature: '',
                //     TotalWeight: '',
                //     ApproveName: '',
                //     Remarks: ''
                // },
                inputCode: '',
                scanShow: false,
                classShow: false,
                IControlActions: [
                    {
                        name: 'OK',
                        value: 1
                    },
                    {
                        name: 'NO',
                        value: 0
                    }
                ],
                classOptions: [
                    {
                        value: '0',
                        name: '白班'
                    },
                    {
                        value: '1',
                        name: '晚班'
                    }
                ],
                tableData: [
                    {
                        SMDetailID: '',
                        WTContent: '',
                        WTAnalysis: ''

                    }
                ],
                AllSMDetailID: '',
                currentIndex: 0,
            },
            created: function () {
                var that = this;
                console.log('waterAPI', JSON.stringify(api.pageParam))
                // console.log('name', JSON.stringify(window.localStorage.getItem('loginName')))
                // that.formData = api.pageParam
                if (api.pageParam.historyData) {
                    that.formData = api.pageParam.historyData
                    that.formData.StartTime = api.pageParam.historyData.StartTime ? api.pageParam.historyData.StartTime.replace('T', ' ') : ''
                    that.formData.CreateTime = api.pageParam.historyData.CreateTime ? api.pageParam.historyData.CreateTime.replace('T', ' ') : ''
                    that.formData.EndTime = api.pageParam.historyData.EndTime ? api.pageParam.historyData.EndTime.replace('T', ' ') : ''
                    that.formData.EquipmentID = api.pageParam.pageParamMsg.equipment.EquipmentID
                    // that.buttonShow = 
                    // APP.ajax('getSMMXLB', { SMDetailID: api.pageParam.historyData.SMDetailID }, function (res) {
                    //     console.log('27270res', JSON.stringify(res))
                    //     that.tableData = res.ds
                    // })
                } else {
                    APP.ajax('getZS_WTAppover', { UserName: window.localStorage.getItem('loginName') }, function (res) {
                        if (res.ds.length) {
                            that.formData.Creater = res.ds[0].EmplName
                        }
                    })
                    that.formData.EquipmentName = api.pageParam.equipment.EquipmentName
                    that.formData.EquipmentCode = api.pageParam.equipment.EquipmentCode
                    that.formData.EquipmentID = api.pageParam.equipment.EquipmentID
                }

                if (window.localStorage.getItem('clientHeight') != 752) {
                    document.getElementById('app').style.zoom = 0
                } else {
                    document.getElementById('app').style.zoom = 1.5
                }

            },
            mounted() {
                APP.keyBoardChange()
            },
            methods: {
                addTime(title) {
                    var that = this

                    that.currentTimeStr = title
                    that.showTime = true
                },
                confirmTime() {
                    var that = this
                    if (that.currentTimeStr == '开始时间') {
                        that.formData.CreateTime = APP.getFormatDate(that.currentDate)
                    } else {
                        that.formData.EndTime = APP.getFormatDate(that.currentDate)
                    }
                    that.showTime = false
                },
                go() {
                    var that = this
                    console.log(JSON.stringify(api.pageParam.pageParamMsg))
                    var obj = {
                        // SMDetailID: 10,
                        SMDetailID: that.formData.SMDetailID,
                        EquipmentID: that.formData.EquipmentID
                    }
                    console.log(JSON.stringify(obj))
                    APP.ajax('getTJKHTML_SM', obj, function (res) {
                        console.log('getTJKHTML_SM', JSON.stringify(res))
                        api.sendEvent({
                            name: 'resetBreadList',
                            extra: {
                                breadData: {
                                    name: '试模新增',
                                    url: 'TryoutDetailsAdd',
                                    ZS_FunctionID: 0,
                                    click: true
                                }
                            }
                        })
                        if (window.localStorage.getItem('clientHeight') != 752) {
                            api.openFrame({
                                name: 'TryoutDetailsAdd',
                                url: 'TryoutDetailsAdd.html',
                                rect: {
                                    x: 0,
                                    y: 115,
                                    w: 'auto',
                                    h: api.winHeight - 150 - api.safeArea.bottom
                                },
                                bgColor: '#29292a',
                                pageParam: {
                                    url: res.ds[0].html,
                                    pageParamMsg: api.pageParam.pageParamMsg,
                                    GUCode: res.ds1[0].GUCode,
                                    SMDetailID: that.formData.SMDetailID,
                                    EquipmentID: that.formData.EquipmentID
                                }
                            })
                        } else {
                            api.openFrame({
                                name: 'TryoutDetailsAdd',
                                url: 'TryoutDetailsAdd.html',
                                rect: {
                                    x: 0,
                                    y: 170,
                                    w: 'auto',
                                    h: api.winHeight - 230 - api.safeArea.bottom
                                },
                                bgColor: '#29292a',
                                pageParam: {
                                    url: res.ds[0].html,
                                    pageParamMsg: api.pageParam.pageParamMsg,
                                    GUCode: res.ds1[0].GUCode,
                                    SMDetailID: that.formData.SMDetailID,
                                    EquipmentID: that.formData.EquipmentID
                                }
                            })
                        }
                    })

                },
                onSelectIControl(val) {
                    var that = this
                    console.log('试制目的', val)
                    that.formData.Result = val.name
                    that.showSearch = false
                },
                openshowSearch(index) {
                    var that = this
                    that.showSearchIndex = index
                    that.showSearch = true
                },
                addUserName() {
                    var that = this
                    that.scanShow = true
                },
                inputFocus() {
                    var that = this
                    console.log('that.inputCode', JSON.stringify(that.inputCode))
                    APP.ajax('ZS_CardLogin', { P_Card: that.inputCode }, function (res) {
                        // console.log('res', JSON.stringify(res))
                        if (res.ds[0].status == 200) {
                            that.formData.EquipmentName = res.ds[0].card_no
                            that.formData.EquipmentCode = res.ds[0].Name
                            vm.$toast(res.ds[0].msg);

                            APP.ajax('ZS_getEmplMessage', { Code: that.formData.EquipmentCode }, function (res) {
                                that.formData.EquipmentID = res.ds[0].EmplID
                            })
                            that.scanShow = false
                        } else {
                            vm.$toast(res.ds[0].msg);
                        }
                        that.inputCode = ''
                    })
                },
                openBaseScreen(str, index) {
                    var that = this
                    var obj;
                    if (str == '机台') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['EquipmentName'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSEquipment',
                            param: {
                            }
                        }
                    }
                    else if (str == '模具') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['MouldNo'],
                            isPaging: false,
                            type: str,
                            cmd: 'getZSMould',
                            param: {
                            }
                        }
                    }

                    api.openWin({
                        name: 'baseScreen',
                        url: 'common/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                onSelectClass(val) {
                    var that = this
                    that.formData.WhiteORNight = val.value
                    that.formData.class = val.name
                    that.classShow = false
                },

                // deleteTable(index) {
                //     var that = this
                //     if (that.tableData.length == 1) {
                //         that.tableData[0].SMDetailID = that.AllSMDetailID
                //         that.tableData[0].WTContent = ''
                //         that.tableData[0].WTAnalysis = ''
                //     } else {
                //         that.tableData.splice(index, 1)
                //     }
                // },
                // addRow() {
                //     var that = this
                //     var newTable = {
                //         SMDetailID: that.AllSMDetailID,
                //         WTContent: '',
                //         WTAnalysis: ''
                //     }
                //     that.tableData.push(newTable)
                // },
                addsubmit() {
                    var that = this
                    var mainObj = {
                        SMDetailID: that.formData.SMDetailID,
                        Creater: that.formData.Creater,
                        Result: that.formData.Result,
                        WTFXContent: that.formData.WTFXContent
                    }
                    console.log('TryoutDetail', JSON.stringify(mainObj))
                    APP.ajax('StartSMGL', mainObj, function (res) {
                        console.log('StartSMGL', JSON.stringify(res))
                        api.toast({
                            msg: '保存成功！',
                            duration: 2000,
                            location: 'bottom'
                        });
                        that.buttonShow = 2
                    })


                },
                endsubmit() {
                    var that = this
                    // that.formData.shangjiaList.map(item => item.SJQty).join(','),
                    var mainObj = {
                        SMDetailID: that.formData.SMDetailID,
                        Creater: that.formData.Creater,
                        Result: that.formData.Result,
                        WTFXContent: that.formData.WTFXContent,
                        WTContent: that.formData.WTContent,
                        EndTime: that.formData.EndTime,
                        CreateTime: that.formData.CreateTime,
                        EndTime: that.formData.EndTime,
                        EquipmentID: that.formData.EquipmentID
                    }
                    APP.ajax('EndSMGL', mainObj, function (res) {
                        console.log('EndSMGL', JSON.stringify(res))
                        that.buttonShow = 1
                        api.sendEvent({
                            name: 'refreshTryoutDetail'
                        })
                        api.sendEvent({
                            name: 'refreshBrowser',
                            extra: {
                                clearName: 'TryoutDetails'
                            }
                        })
                        api.closeFrame()

                    })

                },
                // submit() {
                //     var that = this
                //     var mainObj = {
                //         EquipmentID: that.formData.EquipmentID,
                //         empolorName: that.formData.empolorName,
                //         WhiteORNight: that.formData.WhiteORNight,
                //         StartTime: that.formData.StartTime,
                //         ApproveName: that.formData.ApproveName,
                //         Result: that.formData.Result,
                //         Colour: that.formData.Colour,
                //         CheckTemperature: that.formData.CheckTemperature,
                //         MinTemperature: that.formData.MinTemperature,
                //         MaxTemperature: that.formData.MaxTemperature,
                //         TotalWeight: that.formData.TotalWeight,
                //         Remarks: that.formData.Remarks
                //     }
                //     APP.ajax('getZS_AddPlastic', mainObj, function (mainRes) {
                //         that.tableData.map((item) => {
                //             var subObj = {
                //                 ZS_AddPlasticID: mainRes.ds[0].Column1,
                //                 ProductName: item.ProductName,
                //                 MaterialCode: item.ProductCode,
                //                 Weight: item.Weight,
                //                 MaterialBatch: item.MaterialBatch
                //             }
                //             APP.ajax('getZS_AddPlasticDel', subObj, function (res) {
                //                 if (res.ds[0].status != 200) {
                //                     api.toast({
                //                         msg: '保存失败，请重试！',
                //                         duration: 2000,
                //                         location: 'bottom'
                //                     });
                //                     return false
                //                 }
                //             })
                //         })
                //         api.toast({
                //             msg: '保存成功！',
                //             duration: 2000,
                //             location: 'bottom'
                //         });
                //         api.sendEvent({
                //             name: 'refreshBrowser',
                //             extra: {
                //                 clearName: api.pageParam.name
                //             }
                //         })
                //         api.closeFrame()
                //     })
                // }

            }
        })
    };
</script>

</html>